package com.ttbj.controller.moveRule;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ttbj.api.dto.moveRule.MoveRuleDto;
import com.ttbj.api.exception.BusinessException;
import com.ttbj.api.moveRule.MoveRuleService;
import com.ttbj.constant.annotation.SystemControllerLog;
import com.ttbj.util.ViewDataUtil;

@Controller
public class MoveRuleController {
	
	@Autowired
	private MoveRuleService moveRuleService;
	
	/**
	 * 搬家计费页面
	 * @return
	 */
	@RequestMapping(value="/moverule/move_rule.htm")
	public String move_rule() {
		return "moverule/move_rule";
	}
	
	
	/**
	 * 获取搬家计费信息
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/moverule/getMoveRuleInfo.htm", method=RequestMethod.GET, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	public String getMoveRuleInfo(HttpServletRequest request, HttpServletResponse response) {
		try {
			MoveRuleDto moveRuleDto = this.moveRuleService.findMoveRuleInfo();
			return ViewDataUtil.buildSuccessJson("搬家计费信息", moveRuleDto);
		} catch (BusinessException e) {
			return ViewDataUtil.buildFailureJson(e.getErrorCode(), e.getMessage());
		}
	}
	
	/**
	 * 更新搬家计费信息
	 * @param carriageRuleDto 搬家计费信息
	 * @return
	 */
	@RequestMapping(value="/moverule/modifyMoveRuleInfo.htm", method=RequestMethod.POST, produces={"text/html;charset=UTF-8;","application/json;"})
	@ResponseBody
	@SystemControllerLog(description="修改搬家计费配置")
	public String modifyMoveRuleInfo(MoveRuleDto moveRuleDto) {
		try {
			this.moveRuleService.editMoveRuleInfo(moveRuleDto);
			return ViewDataUtil.buildSuccessJson("更改成功");
		} catch (BusinessException e) {
			return ViewDataUtil.buildFailureJson(e.getErrorCode(), e.getMessage());
		}
	}
}
